package com.agadmin.exception;

import java.util.Objects;

public enum ResponseExceptionEnum {
    SERVER_NO_RES (1001,"服务未响应"),
    SERVER_ARGS_ERROR (1002,"处理参数错误"),
    DATA_NOT_FOUND (1003,"字段校验不通过"),
    ACCOUNT_INCORRECT (1004,"账号或密码错误"),
    TOKEN_INCORRECT (1005,"token错误");
    private int code;
    private String msg;

    ResponseExceptionEnum(int code, String msg){
        this.code=code;
        this.msg=msg;
    }


    // 通过code获取名称
    public static String formName(int code) {
        for (ResponseExceptionEnum c : ResponseExceptionEnum.values()) {
            if (c.getCode() == code) {
                return c.msg;
            }
        }
        return null;
    }
    // 通过名称获取code
    public static Integer formCode(String msg) {
        for (ResponseExceptionEnum c : ResponseExceptionEnum.values()) {
            if (Objects.equals(c.getMsg(), msg)) {
                return c.code;
            }
        }
        return null;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
